<template>
  <div>
    <div class="common-layout">
      <el-container>
        <el-header>
          <el-menu
            :default-active="activeIndex"
            class="el-menu-demo"
            mode="horizontal"
            :ellipsis="false"
            @select="handleSelect"
          >
            <el-menu-item index="0">LOGO</el-menu-item>
            <div class="flex-grow" />
            <el-menu-item :index="item.id" v-for="(item, index) in menuList" :key="index">
              <router-link :to="'/main/' + item.path">{{ item.msg }}</router-link>
            </el-menu-item>
            <el-sub-menu :index="menuList.length + 1">
              <template #title>个人中心</template>
              <el-menu-item index="2-1">修改密码</el-menu-item>
              <el-menu-item index="2-2">退出登录</el-menu-item>
            </el-sub-menu>

            <el-sub-menu :index="menuList.length + 2">
              <template #title>{{ $t('message.lang') }}</template>
              <el-menu-item index="3-1" @click="change('zh')">中文</el-menu-item>
              <el-menu-item index="3-2" @click="change('en')">English</el-menu-item>
            </el-sub-menu>
          </el-menu>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </div>
  </div>
</template>

<script lang="ts" setup>
import  {ref,onMounted}  from  "vue";
import { routerStore } from '../stores/counter'
import  {useRoute} from "vue-router";
import * as i18n from '@/i18n';


let $store = routerStore()
let $route = useRoute();
let menuList: any = $store.menuList;
menuList  = menuList.map((item:any,index:any)=>{
  return  {...item,id:index+1}
})
const activeIndex = ref(1);
onMounted(()=>{
  let path = $route.path;
  

  let  item = menuList.filter((item:any)=>"/main/"+item.path==path)[0];
  if(item){
    activeIndex.value = item.id;
  }

})

const handleSelect = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const change  = (lang:string)=>{
  // locale.value  = lang;
   console.log(i18n);
  // let local  = i18n.useI18n();
  // console.log(local);
  i18n.default.global.locale = lang;
}



      

</script>

<style></style>
